<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="js/tool.js"></script>
    <script src="js/jquery.min.js"></script>

</head>
<body>
<textarea name="comment" id="comment" class="comment" cols="30" rows="10"></textarea>
<button id="submit" onclick="subcomment()"> 点击提交</button>
</body>

<script>
    function subcomment() {
        let text = document.getElementById("comment").value;
        let id = getURLParam("id");
        $.ajax({
            url: "/comment/submit",
            method: "GET",
            data: {
                "content": text,
                "aid": id
            },
            success: function (result) {
                if (result.code == 200 && result.data != null) {
                    alert("发布成功");
                    location.href = "blog_content.html?id=" + id;
                } else {
                    alert(result.msg);
                }
            },
            error: function (err) {
                if (err != null && err.status == 401) {
                    alert("用户未登录，即将跳转到登录页！");
                    // 已经被拦截器拦截了，未登录
                    location.href = "/login.html";
                }
            }

        });
    }

</script>
</html>
